package com.wap.framework.util;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

public class InitServlet extends HttpServlet {

	private static final long serialVersionUID = -132718653240482347L;

	public InitServlet() {
		super();
	}

	public void destroy() {
		super.destroy();
	}

	public void init() throws ServletException {
		ServletContext context = getServletContext();
		String realPath = context.getRealPath("/");
		
		ServletConfig config = getServletConfig();

		String pageAccessUrl = config.getInitParameter("pageAccessUrl");
		if (pageAccessUrl != null && !"".equals(pageAccessUrl)) {
			Constants.PAGE_ACCESS_URL = pageAccessUrl;
		}

		String uploadImagesPath = config.getInitParameter("uploadImagesPath");
		if (uploadImagesPath != null && !"".equals(uploadImagesPath)) {
			Constants.UPLOAD_IMAGES_PATH = realPath + uploadImagesPath;
		}
		
		String wapSitePath = config.getInitParameter("wapSitePath");
		if (wapSitePath != null && !"".equals(wapSitePath)) {
			Constants.WAPSITE_PATH = wapSitePath;
		}
		
		String numPerPage = config.getInitParameter("numPerPage");
		if(numPerPage != null && !"".equals(numPerPage))  {
			Constants.NUMBERS_PER_PAGE = Integer.valueOf(numPerPage);
		} else {
			Constants.NUMBERS_PER_PAGE = 15;
		}
	}
}
